package repodata

import (
	"fmt"
	"os"
	"path/filepath"
	"time"
)

type PackageInfo struct {
}

type RepoInfo struct {
	workspace   string
	packageList []PackageInfo
}

type RepoInfoOption func(info *RepoInfo)

func WithWorkspace(workspace string) RepoInfoOption {
	return func(info *RepoInfo) {
		_ = os.MkdirAll(workspace, os.ModeDir)
		info.workspace = workspace
	}
}

func WithWorkspaceRandom(workspace string) RepoInfoOption {
	return func(info *RepoInfo) {
		workspaceSub := fmt.Sprintf("%v-%v", time.Now().Unix(), GenerateRandomString(3, CharsetLettersDigits))
		workspace = filepath.Join(workspace, workspaceSub)
		_ = os.MkdirAll(workspace, os.ModeDir)
		info.workspace = workspace
	}
}

func NewRepoInfo(opts ...RepoInfoOption) *RepoInfo {
	ri := &RepoInfo{}
	for _, opt := range opts {
		opt(ri)
	}
	return ri
}
